from datetime import datetime,timezone  # timezone 时区设置
from datetime import timedelta  #用于对时间进行加减

# 获取当前时间  2018-10-15 13:16:44.456383
print(datetime.now())

# 获取当前时间的时间戳  1539580604.456383
print(datetime.now().timestamp())


# 新定制一个时间
print(datetime(2018,10,15,0,0,0))

#时间戳 转 时间


timestamp = 1539580656.666383

# 转为本地时间
print(datetime.fromtimestamp(timestamp))

# 转为UTC时间
print(datetime.utcfromtimestamp(timestamp))


# 字符串转时间

time_str = '2018-01-01 00:00:00'

get_time = datetime.strptime(time_str,'%Y-%m-%d %H:%M:%S')

print(get_time)

# 时间转字符串

print(datetime.strftime(get_time,'%Y-%m-%d %H:%M:%S'))

# 1-1 号  加10天  和 减去5天

print(get_time+timedelta(days=10))

print(get_time-timedelta(days=5))